package com.zhu.gmallpublisher.controller;

import com.zhu.gmallpublisher.service.GMVService;
import com.zhu.gmallpublisher.utils.GetDateUtil;
import com.zhu.gmallpublisher.utils.GMVJsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 可视化数据接口 Sugar
 */
@RestController
@RequestMapping("/zhu")
public class GMVController {

    @Autowired
    private GMVService gmvService;


    /**
     * 数据格式
     * {"status": 0,"msg": "","data": 1201083.3357827025}
     * @param selectDate 查询日期
     * @return
     */
    @RequestMapping("/gmv")
    public String getGmv(@RequestParam(value = "date",defaultValue = "0") int selectDate){
        if(selectDate == 0){
            selectDate = GetDateUtil.getCurrentTime();
        }
        Double gmv =  gmvService.getGmv(selectDate);
        //return result
        return GMVJsonUtil.getGMVJson(gmv);
    }




}
